package com.atguigu.crowd.service.impl;

import static org.hamcrest.CoreMatchers.nullValue;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.atguigu.crowd.entity.po.MemberPO;
import com.atguigu.crowd.entity.po.MemberPOExample;
import com.atguigu.crowd.entity.po.MemberPOExample.Criteria;
import com.atguigu.crowd.mapper.MemberPOMapper;
import com.atguigu.crowd.service.api.MemberProviderService;

@Transactional(readOnly=true)
@Service
public class MemberProviderServiceImpl implements MemberProviderService{

	@Autowired
	private MemberPOMapper memberPOMapper;
	
	@Override
	public MemberPO getMemberPOByLoginAcct(String loginAcct) {
		MemberPOExample memberPOExample = new MemberPOExample();
		Criteria criteria = memberPOExample.createCriteria();
		criteria.andLoginacctEqualTo(loginAcct);
		List<MemberPO> memberList = memberPOMapper.selectByExample(memberPOExample);
		if (memberList==null || memberList.size()==0) {
			return null;
		}
		MemberPO memberPO = memberList.get(0);
		return memberPO;
	}

	@Transactional(propagation=Propagation.REQUIRES_NEW,
			rollbackFor=Exception.class,
			readOnly=false)
	@Override
	public void saveMember(MemberPO memberPO) {
		//设置实名状态为未实名
		memberPO.setAuthstatus(0);
		memberPOMapper.insertSelective(memberPO);
	}

}
